import pymysql


class DBTools(object):
    def __conn(self):
        conn = pymysql.Connect(host="121.43.169.97", port=3306,
                               user="student", password="p2p_student_2022",
                               database="czbk_member", charset="utf8")
        return conn

    @staticmethod
    def query_sql(sql):
        my_conn = None
        cur = None
        try:
            cur = DBTools.__conn().cursor()
            cur.execute(sql)
            result = cur.fetchall()
            return result
        except Exception as e:
            return f"异常结果:{e}"

        finally:
            cur.close()
            my_conn.close()

    @staticmethod
    def query_sql(sql):
        my_conn = None
        cur = None
        try:
            cur = DBTools.__conn().cursor()
            cur.execute(sql)
            result = cur.fetchall()
            return result
        except Exception as e:
            return f"异常结果:{e}"

        finally:
            cur.close()
            my_conn.close()
